{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "from sklearn.datasets import load_wine\n",
    "\n",
    "from sklearn.model_selection import train_test_split\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "from sklearn.model_selection import cross_val_score\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签\n",
    "plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "   Fans  sex  borntime  关注数    微博数    互动数  视频累积播放量  关注领域Top1  关注领域Top2  \\\n0  2071    0        69  970  16948  51000    55000        20        29   \n1    21    0        58  114    441    424      172        29        26   \n\n   关注领域Top3  ...  法律  综艺节目  旅游出行  财经  健康医疗  电视剧  EI  NS  FT  PJ  \n0        12  ...   0     0     0   0     0    0   1   1   0   1  \n1        12  ...   0     0     0   0     0    0   1   1   0   1  \n\n[2 rows x 51 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Fans</th>\n      <th>sex</th>\n      <th>borntime</th>\n      <th>关注数</th>\n      <th>微博数</th>\n      <th>互动数</th>\n      <th>视频累积播放量</th>\n      <th>关注领域Top1</th>\n      <th>关注领域Top2</th>\n      <th>关注领域Top3</th>\n      <th>...</th>\n      <th>法律</th>\n      <th>综艺节目</th>\n      <th>旅游出行</th>\n      <th>财经</th>\n      <th>健康医疗</th>\n      <th>电视剧</th>\n      <th>EI</th>\n      <th>NS</th>\n      <th>FT</th>\n      <th>PJ</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2071</td>\n      <td>0</td>\n      <td>69</td>\n      <td>970</td>\n      <td>16948</td>\n      <td>51000</td>\n      <td>55000</td>\n      <td>20</td>\n      <td>29</td>\n      <td>12</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>21</td>\n      <td>0</td>\n      <td>58</td>\n      <td>114</td>\n      <td>441</td>\n      <td>424</td>\n      <td>172</td>\n      <td>29</td>\n      <td>26</td>\n      <td>12</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n<p>2 rows × 51 columns</p>\n</div>"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mbti_weibo_data = pd.read_csv('../data/predata2.csv')\n",
    "mbti_weibo_data.head(2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "data": {
      "text/plain": "     Fans  sex  borntime   关注数    微博数    互动数  视频累积播放量  关注领域Top1  关注领域Top2  \\\n0    2071    0        69   970  16948  51000    55000        20        29   \n1      21    0        58   114    441    424      172        29        26   \n2     373    0         7   115     96    488   332000        29         8   \n3     109    0        87   142     20      5        0        29        20   \n4       5    0        52   277    257    158        0        29         4   \n..    ...  ...       ...   ...    ...    ...      ...       ...       ...   \n156    46    1        81    91    123    315       13        20        29   \n157  1339    0        95   278   1089   2695    21000        29        12   \n158    16    1        64   279    195     81        0        12        29   \n159   491    0        82   193   5602  21000   285000        29        20   \n160   194    1       153  1349  13463  26000    17000         5         6   \n\n     关注领域Top3  ...  读书作家  社会时事  电影  娱乐明星  法律  综艺节目  旅游出行  财经  健康医疗  电视剧  \n0          12  ...     0     0   0     1   0     0     0   0     0    0  \n1          12  ...     1     1   0     1   0     0     0   0     0    0  \n2          35  ...     0     0   0     1   0     0     0   0     0    1  \n3           6  ...     0     0   0     1   0     0     0   0     1    0  \n4           5  ...     1     1   1     1   0     1     1   1     1    0  \n..        ...  ...   ...   ...  ..   ...  ..   ...   ...  ..   ...  ...  \n156        18  ...     0     0   0     1   0     0     0   0     0    0  \n157         5  ...     1     0   0     1   0     1     0   0     0    1  \n158        18  ...     1     0   0     1   0     0     0   0     1    1  \n159        12  ...     1     0   0     1   0     1     0   0     0    0  \n160        12  ...     1     1   1     0   1     0     1   1     1    1  \n\n[161 rows x 47 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Fans</th>\n      <th>sex</th>\n      <th>borntime</th>\n      <th>关注数</th>\n      <th>微博数</th>\n      <th>互动数</th>\n      <th>视频累积播放量</th>\n      <th>关注领域Top1</th>\n      <th>关注领域Top2</th>\n      <th>关注领域Top3</th>\n      <th>...</th>\n      <th>读书作家</th>\n      <th>社会时事</th>\n      <th>电影</th>\n      <th>娱乐明星</th>\n      <th>法律</th>\n      <th>综艺节目</th>\n      <th>旅游出行</th>\n      <th>财经</th>\n      <th>健康医疗</th>\n      <th>电视剧</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2071</td>\n      <td>0</td>\n      <td>69</td>\n      <td>970</td>\n      <td>16948</td>\n      <td>51000</td>\n      <td>55000</td>\n      <td>20</td>\n      <td>29</td>\n      <td>12</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>21</td>\n      <td>0</td>\n      <td>58</td>\n      <td>114</td>\n      <td>441</td>\n      <td>424</td>\n      <td>172</td>\n      <td>29</td>\n      <td>26</td>\n      <td>12</td>\n      <td>...</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>373</td>\n      <td>0</td>\n      <td>7</td>\n      <td>115</td>\n      <td>96</td>\n      <td>488</td>\n      <td>332000</td>\n      <td>29</td>\n      <td>8</td>\n      <td>35</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>109</td>\n      <td>0</td>\n      <td>87</td>\n      <td>142</td>\n      <td>20</td>\n      <td>5</td>\n      <td>0</td>\n      <td>29</td>\n      <td>20</td>\n      <td>6</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>5</td>\n      <td>0</td>\n      <td>52</td>\n      <td>277</td>\n      <td>257</td>\n      <td>158</td>\n      <td>0</td>\n      <td>29</td>\n      <td>4</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>156</th>\n      <td>46</td>\n      <td>1</td>\n      <td>81</td>\n      <td>91</td>\n      <td>123</td>\n      <td>315</td>\n      <td>13</td>\n      <td>20</td>\n      <td>29</td>\n      <td>18</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>157</th>\n      <td>1339</td>\n      <td>0</td>\n      <td>95</td>\n      <td>278</td>\n      <td>1089</td>\n      <td>2695</td>\n      <td>21000</td>\n      <td>29</td>\n      <td>12</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>158</th>\n      <td>16</td>\n      <td>1</td>\n      <td>64</td>\n      <td>279</td>\n      <td>195</td>\n      <td>81</td>\n      <td>0</td>\n      <td>12</td>\n      <td>29</td>\n      <td>18</td>\n      <td>...</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>159</th>\n      <td>491</td>\n      <td>0</td>\n      <td>82</td>\n      <td>193</td>\n      <td>5602</td>\n      <td>21000</td>\n      <td>285000</td>\n      <td>29</td>\n      <td>20</td>\n      <td>12</td>\n      <td>...</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>160</th>\n      <td>194</td>\n      <td>1</td>\n      <td>153</td>\n      <td>1349</td>\n      <td>13463</td>\n      <td>26000</td>\n      <td>17000</td>\n      <td>5</td>\n      <td>6</td>\n      <td>12</td>\n      <td>...</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n<p>161 rows × 47 columns</p>\n</div>"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# mbti_weibo_data.iloc[:,0:47]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "baseFeatures = mbti_weibo_data.iloc[:,0:47]\n",
    "EI = mbti_weibo_data.iloc[:,47]\n",
    "NS = mbti_weibo_data.iloc[:,48]\n",
    "TF = mbti_weibo_data.iloc[:,49]\n",
    "JP = mbti_weibo_data.iloc[:,50]\n",
    "# MBTI = mbti_weibo_data.iloc[:,51]\n",
    "\n",
    "dataSet = []\n",
    "EI_baseFeatures = baseFeatures.join(EI)\n",
    "dataSet.append(EI_baseFeatures)\n",
    "\n",
    "NS_baseFeatures = baseFeatures.join(NS)\n",
    "dataSet.append(NS_baseFeatures)\n",
    "\n",
    "TF_baseFeatures = baseFeatures.join(TF)\n",
    "dataSet.append(TF_baseFeatures)\n",
    "\n",
    "JP_baseFeatures = baseFeatures.join(JP)\n",
    "dataSet.append(JP_baseFeatures)\n",
    "\n",
    "# MBTI_baseFeatures = baseFeatures.join(MBTI)\n",
    "# dataSet.append(MBTI_baseFeatures)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [],
   "source": [
    "def trainModelTest(X,Y):\n",
    "    Xtrain, Xtest, Ytrain, Ytest = train_test_split(X,Y,test_size=0.3)\n",
    "\n",
    "    # print(Ytest)\n",
    "    clf = DecisionTreeClassifier(random_state=0)\n",
    "    rfc = RandomForestClassifier(n_estimators=20, max_depth=4)\n",
    "\n",
    "    clf = clf.fit(Xtrain,Ytrain)\n",
    "    score_c = clf.score(Xtest,Ytest)\n",
    "\n",
    "    rfc = rfc.fit(Xtrain,Ytrain)\n",
    "    score_r = rfc.score(Xtest,Ytest)\n",
    "\n",
    "    print('Single Tree:{}'.format(score_c),'Random Forest:{}'.format(score_r))\n",
    "    return score_r"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [],
   "source": [
    "#特征选择\n",
    "fx = EI_baseFeatures.iloc[:,0:47]\n",
    "fy = EI_baseFeatures.iloc[:,47]\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 161 entries, 0 to 160\n",
      "Data columns (total 23 columns):\n",
      " #   Column    Non-Null Count  Dtype\n",
      "---  ------    --------------  -----\n",
      " 0   Fans      161 non-null    int64\n",
      " 1   sex       161 non-null    int64\n",
      " 2   borntime  161 non-null    int64\n",
      " 3   互动数       161 non-null    int64\n",
      " 4   视频累积播放量   161 non-null    int64\n",
      " 5   关注领域Top1  161 non-null    int64\n",
      " 6   关注领域Top3  161 non-null    int64\n",
      " 7   关注领域Top5  161 non-null    int64\n",
      " 8   颜值        161 non-null    int64\n",
      " 9   搞笑幽默      161 non-null    int64\n",
      " 10  体育        161 non-null    int64\n",
      " 11  动物宠物      161 non-null    int64\n",
      " 12  科学科普      161 non-null    int64\n",
      " 13  游戏        161 non-null    int64\n",
      " 14  军事        161 non-null    int64\n",
      " 15  汽车        161 non-null    int64\n",
      " 16  娱乐明星      161 non-null    int64\n",
      " 17  法律        161 non-null    int64\n",
      " 18  综艺节目      161 non-null    int64\n",
      " 19  财经        161 non-null    int64\n",
      " 20  健康医疗      161 non-null    int64\n",
      " 21  电视剧       161 non-null    int64\n",
      " 22  EI        161 non-null    int64\n",
      "dtypes: int64(23)\n",
      "memory usage: 29.1 KB\n",
      "None\n",
      "Single Tree:0.6122448979591837 Random Forest:0.5306122448979592\n",
      "Single Tree:0.6122448979591837 Random Forest:0.6530612244897959\n",
      "Single Tree:0.5102040816326531 Random Forest:0.5714285714285714\n",
      "0.6530612244897959\n"
     ]
    }
   ],
   "source": [
    "# EI_baseFeatures.corr().loc['EI'].plot(kind='barh',figsize=(4,10))\n",
    "testDF = EI_baseFeatures\n",
    "testY = 'EI'\n",
    "# drop uncorrelated numeric features (threshold <0.2)\n",
    "corr = abs(testDF.corr().loc[testY])\n",
    "# print(corr)\n",
    "corr = corr[corr<0.07]\n",
    "cols_to_drop = corr.index.to_list()\n",
    "# print(cols_to_drop)\n",
    "df = testDF.drop(cols_to_drop, axis=1)\n",
    "print(df.info())\n",
    "# print(df.iloc[:,5])\n",
    "# df.corr().loc[testY].plot(kind='barh',figsize=(4,10))\n",
    "trainModelTest(testDF.iloc[:,0:4],fy)\n",
    "rsfss = trainModelTest(df.iloc[:,0:12],fy)\n",
    "trainModelTest(fx.iloc[:,0:47],fy)\n",
    "print(rsfss)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "Single Tree:0.5510204081632653 Random Forest:0.5306122448979592\n",
      "Single Tree:0.5918367346938775 Random Forest:0.5714285714285714\n",
      "Single Tree:0.5306122448979592 Random Forest:0.5306122448979592\n",
      "1\n",
      "Single Tree:0.5306122448979592 Random Forest:0.7142857142857143\n",
      "Single Tree:0.46938775510204084 Random Forest:0.5714285714285714\n",
      "Single Tree:0.4897959183673469 Random Forest:0.5714285714285714\n",
      "2\n",
      "Single Tree:0.5510204081632653 Random Forest:0.6530612244897959\n",
      "Single Tree:0.5918367346938775 Random Forest:0.6326530612244898\n",
      "Single Tree:0.42857142857142855 Random Forest:0.5102040816326531\n",
      "3\n",
      "Single Tree:0.5918367346938775 Random Forest:0.6530612244897959\n",
      "Single Tree:0.5306122448979592 Random Forest:0.5510204081632653\n",
      "Single Tree:0.6122448979591837 Random Forest:0.5102040816326531\n",
      "4\n",
      "Single Tree:0.6122448979591837 Random Forest:0.6530612244897959\n",
      "Single Tree:0.5714285714285714 Random Forest:0.6326530612244898\n",
      "Single Tree:0.6530612244897959 Random Forest:0.7142857142857143\n",
      "5\n",
      "Single Tree:0.5918367346938775 Random Forest:0.6326530612244898\n",
      "Single Tree:0.6530612244897959 Random Forest:0.5918367346938775\n",
      "Single Tree:0.5102040816326531 Random Forest:0.6122448979591837\n",
      "6\n",
      "Single Tree:0.6326530612244898 Random Forest:0.5306122448979592\n",
      "Single Tree:0.6326530612244898 Random Forest:0.5918367346938775\n",
      "Single Tree:0.5714285714285714 Random Forest:0.6530612244897959\n",
      "7\n",
      "Single Tree:0.46938775510204084 Random Forest:0.7755102040816326\n",
      "Single Tree:0.5306122448979592 Random Forest:0.5306122448979592\n",
      "Single Tree:0.4489795918367347 Random Forest:0.5510204081632653\n",
      "8\n",
      "Single Tree:0.5918367346938775 Random Forest:0.5918367346938775\n",
      "Single Tree:0.6122448979591837 Random Forest:0.5714285714285714\n",
      "Single Tree:0.6122448979591837 Random Forest:0.5918367346938775\n",
      "9\n",
      "Single Tree:0.5102040816326531 Random Forest:0.5306122448979592\n",
      "Single Tree:0.42857142857142855 Random Forest:0.6122448979591837\n",
      "Single Tree:0.46938775510204084 Random Forest:0.5714285714285714\n",
      "10\n",
      "Single Tree:0.6530612244897959 Random Forest:0.5918367346938775\n",
      "Single Tree:0.5918367346938775 Random Forest:0.5102040816326531\n",
      "Single Tree:0.5306122448979592 Random Forest:0.46938775510204084\n",
      "11\n",
      "Single Tree:0.5918367346938775 Random Forest:0.5918367346938775\n",
      "Single Tree:0.5510204081632653 Random Forest:0.4897959183673469\n",
      "Single Tree:0.6122448979591837 Random Forest:0.4489795918367347\n",
      "12\n",
      "Single Tree:0.4897959183673469 Random Forest:0.673469387755102\n",
      "Single Tree:0.5102040816326531 Random Forest:0.6122448979591837\n",
      "Single Tree:0.6530612244897959 Random Forest:0.5102040816326531\n",
      "13\n",
      "Single Tree:0.6326530612244898 Random Forest:0.6326530612244898\n",
      "Single Tree:0.6122448979591837 Random Forest:0.5714285714285714\n",
      "Single Tree:0.5102040816326531 Random Forest:0.5306122448979592\n",
      "14\n",
      "Single Tree:0.5102040816326531 Random Forest:0.6530612244897959\n",
      "Single Tree:0.5918367346938775 Random Forest:0.5510204081632653\n",
      "Single Tree:0.5918367346938775 Random Forest:0.5918367346938775\n",
      "15\n",
      "Single Tree:0.5918367346938775 Random Forest:0.6938775510204082\n",
      "Single Tree:0.5102040816326531 Random Forest:0.5714285714285714\n",
      "Single Tree:0.5510204081632653 Random Forest:0.5714285714285714\n",
      "16\n",
      "Single Tree:0.5918367346938775 Random Forest:0.4897959183673469\n",
      "Single Tree:0.40816326530612246 Random Forest:0.5714285714285714\n",
      "Single Tree:0.6122448979591837 Random Forest:0.5102040816326531\n",
      "17\n",
      "Single Tree:0.5102040816326531 Random Forest:0.4489795918367347\n",
      "Single Tree:0.5510204081632653 Random Forest:0.6530612244897959\n",
      "Single Tree:0.5102040816326531 Random Forest:0.5918367346938775\n",
      "18\n",
      "Single Tree:0.5102040816326531 Random Forest:0.5510204081632653\n",
      "Single Tree:0.5306122448979592 Random Forest:0.5102040816326531\n",
      "Single Tree:0.46938775510204084 Random Forest:0.42857142857142855\n",
      "19\n",
      "Single Tree:0.5510204081632653 Random Forest:0.6326530612244898\n",
      "Single Tree:0.6326530612244898 Random Forest:0.6938775510204082\n",
      "Single Tree:0.5918367346938775 Random Forest:0.5102040816326531\n",
      "0.6938775510204082\n"
     ]
    }
   ],
   "source": [
    "# import modules\n",
    "from sklearn.feature_selection import (SelectKBest, chi2, SelectPercentile, SelectFromModel, SequentialFeatureSelector, SequentialFeatureSelector)\n",
    "\n",
    "# select K best features\n",
    "bestrsf = 0\n",
    "for k in range(20):\n",
    "    print(k)\n",
    "    X_best = SelectKBest(chi2, k=10).fit_transform(fx,fy)\n",
    "\n",
    "    # number of best features\n",
    "    X_best.shape[1]\n",
    "\n",
    "    trainModelTest(fx.iloc[:,0:4],fy)\n",
    "\n",
    "    rsfs = trainModelTest(X_best,fy)\n",
    "    if rsfs >bestrsf:\n",
    "        bestrsf = rsfs\n",
    "    trainModelTest(fx.iloc[:,0:47],fy)\n",
    "print(bestrsf)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2127-09-20 23:32:40.614256\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "import datetime\n",
    "def stampToTime(timestamp):\n",
    "    dt_object = datetime.datetime.fromtimestamp(timestamp / 1000000)\n",
    "    print(dt_object)\n",
    "\n",
    "stampToTime(4977127960614256)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}